package com.we.weblog.mapper;


import com.we.weblog.domain.Game;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface GameMapper {
    //添加游戏
    @Insert({"INSERT INTO t_game (game_name,game_img,game_detail,category_id,tag_id)" +
            "VALUES(#{game.gameName},#{game.gameImg},#{game.gameDetail},#{game.categoryId},#{game.tagId})"})
    int addGame(@Param("game") Game game);

    //修改游戏
    @Update({"update t_game set game_name = #{game.gameName},game_img = #{game.gameImg}," +
            "game_detail = #{game.gameDetail},category_id = #{game.categoryId},tag_id = #{game.tagId}" +
            " where game_id = #{game.gameId}"})
    int updateGameById(@Param("game") Game game);

    //删除游戏
    @Delete({"delete from t_game where game_id = #{id}"})
    int deleteGameById(@Param("id") String id);

    //按照Id查询游戏
    @Select({"select *from t_game t where t.game_id = #{id}"})
    @Results(id = "gameMap", value = {
            @Result(column = "game_id", property = "gameId", javaType = Integer.class, id = true),
            @Result(column = "game_name", property = "gameName", javaType = String.class),
            @Result(column = "game_img", property = "gameImg", javaType = String.class),
            @Result(column = "game_detail", property = "gameDetail", javaType = String.class),
            @Result(column = "category_id", property = "categoryId", javaType = Integer.class),
            @Result(column = "tag_id", property = "tagId", javaType = Integer.class)
    })
    Game selectGameId(@Param("id") String id);

    //查询所有游戏
    @Select({"select *from t_game"})
    @ResultMap("gameMap")
    List<Game> selectGame();

    //按照分类查询游戏
    @Select({"select *from t_game t where t.category_id = #{categoryId}"})
    @ResultMap("gameMap")
    List<Game> selectGameByCategory(@Param("categoryId") String categoryId);

    //按照标签查询游戏
    @Select({"select *from t_game t where t.tag_id = #{tagId}"})
    @ResultMap("gameMap")
    List<Game> selectGameByTag(@Param("tagId") String tagId);
}
